#ifndef DEVICEWIDGET_H
#define DEVICEWIDGET_H

#include "adaptivewidgets.h"
#include "waitdialog.h"
#include "dmcomm.h"

class DevWidget : public AGroupBox
{
    Q_OBJECT
public:
    explicit DevWidget(const DevInfo &info, QWidget *parent = nullptr);
    ~DevWidget();
    DevInfo info() const;
private slots:
    void buttonToggled(bool checked);
signals:
    void openDevice(DevInfo);
    void closeDevice(DevInfo);
private:
    const DevInfo m_info;
    APushButton *button;
    WaitDialog *waitDialog;
};

class HIDWidget : public DevWidget
{
    Q_OBJECT
public:
    explicit HIDWidget(const DevInfo &info, QWidget *parent = nullptr);
private slots:
private:
    ALabel *vidLabel;
    ALabel *pidLabel;
    // ALabel *uidLabel;
    ALineEdit *vidLineEdit;
    ALineEdit *pidLineEdit;
    // ALineEdit *uidLineEdit;
};

class SerialWidget : public DevWidget
{
    Q_OBJECT
public:
    explicit SerialWidget(const DevInfo &info, QWidget *parent = nullptr);
private slots:
private:
    ALabel *serialLabel;
    ALabel *baudRateLabel;
    ALineEdit *serialLineEdit;
    ALineEdit *baudRateLineEdit;
};

class DeviceWidget : public AGroupBox
{
    Q_OBJECT
public:
    explicit DeviceWidget(QWidget *parent = nullptr);
public slots:
    void createVirtualDevice();
protected:
    void serachClicked();
private:
    void createDevice(const std::vector<DevInfo> &infos);
    bool isInfoExistsInList(const DevInfo &targetInfo);
private:
    AScrollArea *scrollArea;
    AWidget *widget;
    APushButton *searchButton;
    QList<DevWidget *> m_list;
    QVBoxLayout *devLayout;
};

#endif // DEVICEWIDGET_H
